package com.xgkj.diyiketang.task;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.data.AreaInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by XCKJ_Paladowow on 2016/3/21.
 */
public class CityListTask extends CouponHttpBaseTask {

    public CityListTask() {
        super(TaskType.CITYLIST_TASK);
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        Log.e("processResponseData", ": " + respJson.toJSONString());
        List<AreaInfo> list = new ArrayList<AreaInfo>();
        list = JSON.parseArray(respJson.getString(ProtocolConst.LIST_TAG), AreaInfo.class);
        notifyTaskCompleted(TaskResultCode.SUCCESS, list);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(
                    RequestType.CITYLIST_REQUEST);
            request.setApiNo(ApiNo.CITYLIST);
            addRequest(request);
        }
    }
}
